package com.xuecheng.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.api.system.model.dto.DictionaryDTO;
import com.xuecheng.common.util.StringUtil;
import com.xuecheng.system.convert.DictionaryConvert;
import com.xuecheng.system.entity.Dictionary;
import com.xuecheng.system.mapper.DictionaryMapper;
import com.xuecheng.system.service.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {

    /**
     * <p>
     * 根据字典代码查询字典数据信息
     * </p>
     *
     * @param code 数据字典代码
     * @return DictionaryDTO
     */
    @Override
    public DictionaryDTO getByCode(String code) {

        Dictionary dictionary = new Dictionary();
        if (StringUtil.isNotBlank(code)) {
            dictionary = getOne(lambdaQuery().eq(Dictionary::getCode, code));
        }
        return DictionaryConvert.INSTANCE.dictionaryToDto(dictionary);
    }

    /**
     * <p>
     * 查询所有字典数据信息
     * </p>
     *
     * @return List<DictionaryDTO>
     */
    @Override
    public List<DictionaryDTO> queryAll() {
        List<Dictionary> list = this.list();
        return DictionaryConvert.INSTANCE.dictionaryToDtoList(list);
    }
}
